package leetcode.L500;

import java.util.HashSet;
import java.util.Set;

public class EX3 {
    public static int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<Character>();
        int j = 0;
        int res = 0;
        int len = 0;
        for(int i = 0 ; i < s.length() ; i++){
            char t = s.charAt(i);
            while(j<i && set.contains(t)){
                set.remove(s.charAt(j++));
                len--;
            }
            set.add(t);
            len++;
            res = Math.max(res,len);
        }
        return res;
    }

    public static void main(String[] args) {
        lengthOfLongestSubstring("abcabcbb");
    }
}
